home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / gltron.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-10  |  3.6 KB  |  175 lines  |  [TEXT/CWIE]

  1. /*
  2.   gltron
  3.   Copyright (C) 1999 by Andreas Umbach <marvin@dataway.ch>
  4. */
  5.  
  6. #include "gltron.h"
  7.  
  8. /* todo: define the globals where I need them */
  9. /* declare them only in gltron.h */
  10. /* #include "globals.h" */
  11.  
  12. void displayGame() {
  13.   drawGame();
  14.   SystemSwapBuffers();
  15. }
  16.  
  17. int initWindow() {
  18.   int win_id;
  19.   int flags;
  20.   unsigned char fullscreen = 0;
  21.   /* char buf[20]; */
  22.  
  23.   SystemInitWindow(0, 0, game->settings->width, game->settings->height);
  24.  
  25.   SystemHidePointer();
  26.   if(game->settings->windowMode == 0) {
  27.     fullscreen = SYSTEM_FULLSCREEN;
  28.   }
  29.  
  30.   flags = SYSTEM_RGBA | SYSTEM_DOUBLE | SYSTEM_DEPTH;
  31.   SystemInitDisplayMode(flags, fullscreen);
  32.  
  33.   win_id = SystemCreateWindow("gltron");
  34.  
  35.   if (win_id < 0) {
  36.     printf("could not create window...exiting\n");
  37.     exit(1);
  38.   }
  39.  
  40.   if(game->settings->windowMode == 0 || game->settings->mouse_warp == 1) {
  41.     SystemGrabInput();
  42.   }
  43.  
  44.   return win_id;
  45. }
  46.  
  47. void reshape(int x, int y) {
  48.   if(x < game->settings->height || x < game->settings->width)
  49.     initGameScreen();
  50.   if(x > game->settings->width )
  51.     game->screen->vp_x = (x - game->settings->width) / 2;
  52.   if(y > game->settings->height )
  53.     game->screen->vp_y = (y - game->settings->height) / 2;
  54.   changeDisplay();
  55. }
  56.  
  57. void shutdownDisplay(gDisplay *d) {
  58.   deleteTextures(d);
  59.   deleteFonts();
  60.   deleteBitmaps(d);
  61.   SystemDestroyWindow(d->win_id);
  62.   printf("window destroyed\n");
  63. }
  64.  
  65. void setupDisplay(gDisplay *d) {
  66.   printf("trying to create window\n");
  67.   d->win_id = initWindow();
  68.   printf("window created\n");
  69.   printRendererInfo();
  70.   /* printf("win_id is %d\n", d->win_id); */
  71.   printf("loading fonts...\n");
  72.   initFonts();
  73.   printf("loading textures...\n");
  74.   initTexture(game->screen);
  75.   initBitmaps(game->screen);
  76.   SystemReshapeFunc(reshape);
  77. }
  78.  
  79. int main( int argc, char *argv[] ) {
  80.   char *path;
  81.   list *l;
  82. #ifdef SOUND
  83.   int c;
  84. #endif
  85.  
  86. #ifdef __FreeBSD__
  87.   fpsetmask(0);
  88. #endif
  89.  
  90.   SystemInit(&argc, argv);
  91.  
  92. #ifndef CURRENT_EQ_DATA_DIR
  93.   goto_installpath(argv[0]);
  94. #endif
  95.  
  96.   path = getFullPath("settings.txt");
  97.   if(path != NULL)
  98.     initMainGameSettings(path); /* reads defaults from ~/.gltronrc */
  99.   else {
  100.     printf("fatal: could not settings.txt, exiting...\n");
  101.     exit(1);
  102.   }
  103.  
  104.   parse_args(argc, argv);
  105.  
  106.   /* initialize artpack list */
  107.   initArtpacks();
  108.  
  109.   /* sound */
  110.   path = getMusicPath(MUSIC_DIR);
  111.   game->settings->soundList = 
  112.     readDirectoryContents(path, SONG_PREFIX);
  113.   
  114.   game->settings->soundIndex = -1;
  115.  
  116.   l = game->settings->soundList;
  117.  
  118. #ifdef SOUND
  119.   printf("initializing sound\n");
  120.   initSound();
  121.   setFxVolume(game->settings->fxVolume);
  122.  
  123.   if(l->next != NULL) {
  124.     char *tmp;
  125.     tmp = malloc(strlen(path) + 1 + /* seperator */
  126.          strlen((char*) l->data) + 1);
  127.     sprintf(tmp, "%s%c%s", path, SEPERATOR, 
  128.         (char*) l->data);
  129.     fprintf(stderr, "loading song %s\n", tmp);
  130.     loadSound(tmp);
  131.     free(tmp);
  132.     game->settings->soundIndex = 0;
  133.   }
  134.  
  135.   c = 0;
  136.   while(l->next != NULL) {
  137.     l = l->next;
  138.     c++;
  139.   }
  140.   game->settings->soundSongCount = c;
  141.  
  142.   if(game->settings->playMusic)
  143.     playSound();
  144.   setMusicVolume(game->settings->musicVolume);
  145.   free(path);
  146. #endif
  147.  
  148.   printf("loading menu\n");
  149.   path = getFullPath("menu.txt");
  150.   if(path != NULL)
  151.     pMenuList = loadMenuFile(path);
  152.   else {
  153.     printf("fatal: could not load menu.txt, exiting...\n");
  154.     exit(1);
  155.   }
  156.   printf("menu loaded\n");
  157.   free(path);
  158.  
  159.   consoleInit();
  160.   initGameStructures();
  161.   resetScores();
  162.  
  163.   setupDisplay(game->screen);
  164.   switchCallbacks(&guiCallbacks);
  165.   switchCallbacks(&guiCallbacks);
  166.  
  167.   SystemMainLoop();
  168.  
  169.   return 0;
  170. }
  171.  
  172. callbacks gameCallbacks = { 
  173.   displayGame, idleGame, keyGame, initGame, exitGame, initGLGame, gameMouse, gameMouseMotion
  174. };
  175.